package mytest.wd;

public class Test10 {

    public static void main(String[] args) {
        String BLACK_LIST_SQL = "INSERT INTO namelist.user_b_type_list (phone, `status`, change_date)\n" +
                "select \n" +
                "phone,\n" +
                "1 as `status`,\n" +
                "created_ng_time\n" +
                "from \n" +
                "(select \n" +
                "phone,\n" +
                "stage,\n" +
                "created_ng_time,\n" +
                "ROW_NUMBER() OVER ( PARTITION BY phone ORDER BY created_ng_time ASC) AS row_num\n" +
                "from \n" +
                "namelist.user_order_status_list\n" +
                "WHERE stage in ('pd1-5', 'pd6-15')) b\n" +
                "where \n" +
                "b.row_num = 1\n" +
                "and phone in \n" +
                "(SELECT\n" +
                "distinct phone\n" +
                "from\n" +
                "(select\n" +
                "phone,\n" +
                "stage,\n" +
                "created_ng_time,\n" +
                "RANK() OVER (PARTITION BY phone ORDER BY created_ng_time desc) AS rank\n" +
                "from\n" +
                "namelist.user_order_status_list\n" +
                ") a\n" +
                "where a.rank = 1\n" +
                "and a.stage in ('pd1-5', 'pd6-15'))";
        System.out.println(BLACK_LIST_SQL);
    }

}
